# -*- coding: utf-8 -*-
"""
Created on Fri Apr 25 11:00:05 2025

@author: ravem
"""
import base64 
import re

# 正则表达式匹配电子邮件
text_pattern_x = r'<Data item="5" minimum="-0.8921144" maximum="0.50572699" dataFormat="Base64/LE">([\s\S]*?)</Data>'
text_pattern_y = r'<Data item="6" minimum="-1.7064641" maximum="-0.26092049" dataFormat="Base64/LE">([\s\S]*?)</Data>'
text_pattern_z = r'<Data item="7" minimum="-0.69935709" maximum="0.69962811" dataFormat="Base64/LE">([\s\S]*?)</Data>'

character='xyz'

# 读取文件
with open('X_position.xml', 'r', encoding='utf-8') as file:
    content = file.read()

# 查找所有匹配字段
text_match_x = re.findall(text_pattern_x, content)
text_match_x = text_match_x[0]
#text_match_x = str.replace(text_match_x[0],"")
text_match_y = re.findall(text_pattern_y, content)
text_match_y = text_match_y[0]
#text_match_y = str.replace(text_match_y[0],"")
text_match_z = re.findall(text_pattern_z, content)
text_match_z = text_match_z[0]
#text_match_z = str.replace(text_match_z[0],"")

# 输出结果
filename_x='x_position.txt'
filename_y='y_position.txt'
filename_z='z_position.txt'

with open(filename_x,'w', encoding='utf-8') as file:
    file.write(text_match_x)
    print("已创建"+filename_x)

with open(filename_y,'w', encoding='utf-8') as file:
    file.write(text_match_y)
    print("已创建"+filename_y)

with open(filename_z,'w', encoding='utf-8') as file:
    file.write(text_match_z)
    print("已创建"+filename_z)

text_match_x_d = base64.b64decode(text_match_x)
text_match_y_d = base64.b64decode(text_match_y)
text_match_z_d = base64.b64decode(text_match_z)

